<?php

// TITLE: donation
// FILE: donation.php
// AUTHOR: dantira
// CREATED: Mar 21, 2015, 4:52:38 PM
?>

		public function createDonation($donationId, $donorId, $date, $details, $typeId, $purposeId, $pledgeId, $whoEntered, $whenEntered, $whoAuthorized, $whenAuthorized, $donationcol) {
			global $con;
			$sql = 'INSERT INTO donation (donation_id, donor_id, date, details, type_id, purpose_id, pledge_id, who_entered, when_entered, who_authorized, when_authorized, donationcol) VALUES (' . $donationId . ', ' . $donorId . ', ' . $date . ', ' . $details . ', ' . $typeId . ', ' . $purposeId . ', ' . $pledgeId . ', ' . $whoEntered . ', ' . $whenEntered . ', ' . $whoAuthorized . ', ' . $whenAuthorized . ', ' . $donationcol . ')';
			$this->open();
			$result = mysqli_query($con, $sql);
			$id = ($result) ? mysqli_insert_id($con) : $result;
			$this->close();
			return $id;
		}// end function

		public function readDonation($id) {
			global $con;
			$sql = 'SELECT * FROM donation WHERE id = ' . $id;
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$result = mysqli_fetch_array($results);
				$donation = new Donation();
				$donation->setDonationId($this->readDonation($result[0]));
				$donation->setDonorId($this->readDonor($result[1]));
				$donation->setDate($result[2]);
				$donation->setDetails($result[3]);
				$donation->setTypeId($this->readType($result[4]));
				$donation->setPurposeId($this->readPurpose($result[5]));
				$donation->setPledgeId($this->readPledge($result[6]));
				$donation->setWhoEntered($result[7]);
				$donation->setWhenEntered($result[8]);
				$donation->setWhoAuthorized($result[9]);
				$donation->setWhenAuthorized($result[10]);
				$donation->setDonationcol($result[11]);
			} else {
				$donation = false;
			}
			return $donation;
		}// end function

		public function updateDonation($donationId, $donorId, $date, $details, $typeId, $purposeId, $pledgeId, $whoEntered, $whenEntered, $whoAuthorized, $whenAuthorized, $donationcol) {
			global $con;
			$sql = 'UPDATE donation SET donation_id = ' . $donation_id . ', donor_id = ' . $donorId . ', date = ' . $date . ', details = ' . $details . ', type_id = ' . $typeId . ', purpose_id = ' . $purposeId . ', pledge_id = ' . $pledgeId . ', who_entered = ' . $whoEntered . ', when_entered = ' . $whenEntered . ', who_authorized = ' . $whoAuthorized . ', when_authorized = ' . $whenAuthorized . ', donationcol = ' . $donationcol . ' WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function deleteDonation($id) {
			global $con;
			$sql = 'DELETE FROM donation WHERE donation_id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function listDonation() {
			global $con;
			$sql = 'SELECT * FROM donation';
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$donations = array();
				while ($result = mysqli_fetch_array($results)) {
					$donation = new Donation();
					$donation->setDonationId($this->readDonation($result[0]));
					$donation->setDonorId($this->readDonor($result[1]));
					$donation->setDate($result[2]);
					$donation->setDetails($result[3]);
					$donation->setTypeId($this->readType($result[4]));
					$donation->setPurposeId($this->readPurpose($result[5]));
					$donation->setPledgeId($this->readPledge($result[6]));
					$donation->setWhoEntered($result[7]);
					$donation->setWhenEntered($result[8]);
					$donation->setWhoAuthorized($result[9]);
					$donation->setWhenAuthorized($result[10]);
					$donation->setDonationcol($result[11]);
					$donations[] = $donation;
				}// end while
			} else {
				$donations = false;
			}
			return $donations;
		}// end function

		// donation_type // --------------------

		public function createDonationType($typeId, $title, $code, $description) {
			global $con;
			$sql = 'INSERT INTO donation_type (type_id, title, code, description) VALUES (' . $typeId . ', ' . $title . ', ' . $code . ', ' . $description . ')';
			$this->open();
			$result = mysqli_query($con, $sql);
			$id = ($result) ? mysqli_insert_id($con) : $result;
			$this->close();
			return $id;
		}// end function

		public function readDonationType($id) {
			global $con;
			$sql = 'SELECT * FROM donation_type WHERE id = ' . $id;
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$result = mysqli_fetch_array($results);
				$donationType = new DonationType();
				$donationType->setTypeId($this->readType($result[0]));
				$donationType->setTitle($result[1]);
				$donationType->setCode($result[2]);
				$donationType->setDescription($result[3]);
			} else {
				$donationType = false;
			}
			return $donationType;
		}// end function

		public function updateDonationType($typeId, $title, $code, $description) {
			global $con;
			$sql = 'UPDATE donation_type SET type_id = ' . $type_id . ', title = ' . $title . ', code = ' . $code . ', description = ' . $description . ' WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function deleteDonationType($id) {
			global $con;
			$sql = 'DELETE FROM donation_type WHERE type_id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function listDonationType() {
			global $con;
			$sql = 'SELECT * FROM donation_type';
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$donationTypes = array();
				while ($result = mysqli_fetch_array($results)) {
					$donationType = new DonationType();
					$donationType->setTypeId($this->readType($result[0]));
					$donationType->setTitle($result[1]);
					$donationType->setCode($result[2]);
					$donationType->setDescription($result[3]);
					$donationTypes[] = $donationType;
				}// end while
			} else {
				$donationTypes = false;
			}
			return $donationTypes;
		}// end function

// purpose // --------------------

		public function createPurpose($id, $title, $description) {
			global $con;
			$sql = 'INSERT INTO purpose (id, title, description) VALUES (' . $id . ', ' . $title . ', ' . $description . ')';
			$this->open();
			$result = mysqli_query($con, $sql);
			$id = ($result) ? mysqli_insert_id($con) : $result;
			$this->close();
			return $id;
		}// end function

		public function readPurpose($id) {
			global $con;
			$sql = 'SELECT * FROM purpose WHERE id = ' . $id;
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$result = mysqli_fetch_array($results);
				$purpose = new Purpose();
				$purpose->setId($result[0]);
				$purpose->setTitle($result[1]);
				$purpose->setDescription($result[2]);
			} else {
				$purpose = false;
			}
			return $purpose;
		}// end function

		public function updatePurpose($id, $title, $description) {
			global $con;
			$sql = 'UPDATE purpose SET title = ' . $title . ', description = ' . $description . ' WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function deletePurpose($id) {
			global $con;
			$sql = 'DELETE FROM purpose WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function listPurpose() {
			global $con;
			$sql = 'SELECT * FROM purpose';
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$purposes = array();
				while ($result = mysqli_fetch_array($results)) {
					$purpose = new Purpose();
					$purpose->setId($result[0]);
					$purpose->setTitle($result[1]);
					$purpose->setDescription($result[2]);
					$purposes[] = $purpose;
				}// end while
			} else {
				$purposes = false;
			}
			return $purposes;
		}// end function

		
